function showDataDictionarySearch(){
	window.location.href="showDataDictionarySearch.do";
}

function ajaxFindDataDictionarySearchList(parentCode,name) {
	$.ajax({
		type:"post",
		url: "ajaxDataDictionarySearchList.do",
		data:{parentcode:parentCode},
		success:function(msg){
			$("#name").text(name);
			$("#listDataDictionaryBox").html(msg);
		}
	});
}

function ajaxDataDictionaryTreeMenu(){
	$.ajax({
		type:"post",
		url: "ajaxDataDictionaryTreeMenu.do",
		success:function(msg){
			$("#leftDataDictionaryBox").html(msg);
		}
	});
	
}

//����
function getJsForMenu() {
	$('#menu a.item').click(function () {

		//slideup or hide all the Submenu
		$('#menu li').children('ul').slideUp('fast');	

		//remove all the "Over" class, so that the arrow reset to default
		$('#menu a.item').each(function () {
			if ($(this).attr('rel')!='') {
				$(this).removeClass($(this).attr('rel') + 'Over');	
			}
		});

		//show the selected submenu
		$(this).siblings('ul').slideDown('fast');

		//add "Over" class, so that the arrow pointing down
		$(this).addClass($(this).attr('rel') + 'Over');			

		return false;

	});
}

/*-----DataDictionaryEdit Function */
function ajaxShowDataDictionaryEdit(id){
	$.ajax({
		type:"post",
		url:"ajaxShowDataDictionaryEdit.do",
		data:{id:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 800,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons: [
				          {
				        	  text: "保存",
				        	  click: function() {
				        		  ajaxSaveDataDictionary(this);
				        	  }
				          },
				          {
				        	  text: "关闭",
				        	  click: function() {
				        		  $(this).dialog( "close" );
				        	  }
				          }
				          ]
			});
		}
	});
}

function ajaxSaveDataDictionary(objDialog) {
	dataDictionaryValidate();
	if ($("#frmDataDictionary").valid()) {
		$(objDialog).dialog("close");
		var options ={
				type: "post",
				url : "ajaxSaveDataDictionary.do",
				success: function (msg) {
					ajaxFindDataDictionarySearchList(1);
					showMessageDialog("保存套牌车","套牌车信息保存成功。",null,dialogType.info);
				}
			};
		$("#frmDataDictionary").ajaxSubmit(options);
	}
}

function ajaxShowDataDictionaryView(id){
	$.ajax({
		type:"post",
		url:"ajaxShowDataDictionaryView.do",
		data:{id:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 800,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons : [ {
					text : "关闭",
					click : function() {
						$(this).dialog("close");
					}
				} ]
			});
		}
	});
}

function ajaxDeleteDataDictionaryById(id) {
	var dataDictionaryIds="";
	var sltDD = $("#listDataDictionaryList tbody input:checked").length;
	if(id==null){
		$("#listDataDictionaryList tbody input:checked").each(function(){ 
			dataDictionaryIds += $(this).val()+",";
		});
		if (dataDictionaryIds == ""){
			alert("请选择一行或多行");
			return;
		}else{
			dataDictionaryIds=dataDictionaryIds.substring(0, dataDictionaryIds.length-1);
		}
	}else{
		dataDictionaryIds=id;
		sltDD = 1;
	}
	if( dataDictionaryIds!=null) {
		showMessageDialog("删除数据字典","确定要删除所选“"+sltDD+"”条数据字典记录吗？",
		function () {
			$.ajax({					
				type:"post",
				url:"ajaxDeleteDataDictionaryByIds.do",
				data:{dataDictionaryIds:dataDictionaryIds},
				success:function(msg){
					ajaxFindDataDictionarySearchList($("#rvimsSysCodeParentCode").val());
					showMessageDialog("提示","数据字典删除成功",null,dialogType.info);
				}
			});
			}
		,dialogType.warning);
	}
}

function dataDictionaryValidate(){
	$("#frmDataDictionary").validate({
		errorLabelContainer: $("#infoDataDictionary"),
		rules : {
			code : {
				required :true				
			},
			name : {
				required :true				
			}
		},
		messages : {
			code : {
				required :"编码不能为空！"
			},
			name : {
				required :"名称不能为空！"
			}
		},
		success: function(label) {
			label.html("&nbsp;");
		}
	});
}